package com.scpii.universal.pns.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.scpii.universal.hibernate.dao.impl.BaseDaoImpl;
import com.scpii.universal.pns.dao.PnsUserMessageDevicesDao;
import com.scpii.universal.pns.entity.PnsUserMessageDevices;

@Repository
public class PnsUserMessageDevicesDaoImpl extends
		BaseDaoImpl<PnsUserMessageDevices, Long> implements
		PnsUserMessageDevicesDao {

	@Override
	public void removeByMessageId(Long messageId) {
		String hql = "DELETE FROM PnsUserMessageDevices WHERE messageId=:messageId";
		Session session = getSession();
		Query query = session.createQuery(hql);
		query.setParameter("messageId", messageId);
		query.executeUpdate();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<PnsUserMessageDevices> getMessageByMessageId(Long messageId) {
		String hql = "FROM PnsUserMessageDevices WHERE messageId=:messageId";
		Session session = getSession();
		Query query = session.createQuery(hql);
		query.setParameter("messageId", messageId);
		return query.list();
	}

}
